<?php // no direct access
defined('_JEXEC') or die('Restricted access');

$show_id = $this->show_id;
$show_subject = $this->show_subject;
$show_datetime = $this->show_datetime;

$newsletter_order = $this->newsletter_order;

?>
<div class="nspro componentheading"><?php print JText::_('Newsletter Archive'); ?></div><br/>
<?php

$db =& JFactory::getDBO();

$nquery = 'SELECT * FROM `#__nspro_newsletters` WHERE `sent` = "1"';

switch ($newsletter_order) {
    case '0':
      $order = ' ORDER BY `id` ASC';
      break;
    case '1':
      $order = ' ORDER BY `id` DESC';
      break;
    case '2':
      $order = ' ORDER BY `datetime` ASC';
      break;
    case '3':
      $order = ' ORDER BY `datetime` DESC';
      break;
    case '4':
      $order = ' ORDER BY `subject` ASC';
      break;
    case '5':
      $order = ' ORDER BY `subject` DESC';
      break;
}

$nquery = $nquery . $order;

$db->setQuery($nquery);
$mNewsletters = $db->loadObjectList();

if (count($mNewsletters) > 0) {
  print '<table cellpadding="2" class="nspro nsprotable" id="nsprotablelist">';
  if ($show_id == true) {
    print '<tr style="border: none;"><th style="padding: 2px; border: none;">'. JText::_('ID') . '</th>';
  }
  if ($show_subject == true) {
    print '<th style="padding: 2px; border: none;">'. JText::_('Subject') . '</th>';
  }
  if ($show_datetime == true) {
    print '<th style="padding: 2px; border: none;">'. JText::_('Date and Time Sent') . '</th>';
  }
  print '<th style="padding: 2px; border: none;">'. JText::_('View') .'</th></tr>';
  foreach ($mNewsletters as $mnl) {
    $myLink = 'index.php?option=com_nspro&amp;layout=newsletterview&amp;nid=' . $mnl->id;
    if ($show_id == true) {
      print '<tr style="border: none;"><td style="padding: 2px; border: none;">' . $mnl->id . '</td>';
    }
    if ($show_subject == true) {
      print '<td style="padding: 2px; border: none;">' . $mnl->subject . '</td>';
    }
    if ($show_datetime == true) {
      print '<td style="padding: 2px; border: none;">' . $mnl->datetime . '</td>';
    }
    print '<td style="padding: 2px; border: none;"><a href="' . $myLink . '">' . JText::_('View') . '</a></td></tr>';
  }
  print '</table>';
}
else {
  print JText::_('No Newsletters found.');
}

?>

